<template>
	<view class="work-container">
		<scroll-view class="scroll-view_H" scroll-y="true">
			<view class="zp-item flex flex-column p-20" v-for="(item,index) in dataList" :key="index" @click="clickItem(item)">
				<view class="item-title">
					<text>{{item.name}}</text>
					<view class="btn" @click.stop="goRegister(item)">
						去挂号
					</view>
				</view>
				<text class="color-323232 m-t-15 f-s-28">{{item.address}}</text>
				<text class="color-999 m-t-15 f-s-28">{{item.articleTitle}}</text>
			</view>
		</scroll-view>

		<!-- <z-paging ref="paging" v-model="dataList" @query="queryList">
			<view class="zp-item flex flex-column p-20" v-for="(item,index) in dataList" :key="index" @click="clickItem(item)">
				<view class="item-title">
					<text>{{item.name}}</text>
				</view>
				<text class="color-323232 m-t-15 f-s-28">{{item.address}}</text>
				<text class="color-999 m-t-15 f-s-28">{{item.articleTitle}}</text>
			</view>
		</z-paging> -->
	</view>
</template>

<script>
	import {
		getAllHospital
	} from "@/api/home/home.js";
	import { EventBus } from "@/utils/event-bus.js";
	export default {
		data() {
			return {
				dataList: []
			}
		},
		onLoad: function() {
			this.getData()
		},
		methods: {
			goRegister(res) {
				let params = {
					name: res.name,
					hospitalCode: res.hospitalCode
				}
				uni.setStorageSync('hospital', JSON.stringify(params) || '')
				if (res.aaa == 100) { //有挂号须知进入挂号须知页面 判断条件随便写的

				} else { //没有就跳到选择科室
					this.$tab.navigateTo('/pages/mine/selectDepartment/index')
				}
			},
			clickItem(res) {
				EventBus.$emit('homeIndex', res)
				let params = {
					name: res.name,
					hospitalCode: res.hospitalCode
				}
				uni.setStorageSync('hospital', JSON.stringify(params) || '')
				if (getCurrentPages().length == 1) {
					history.back()
				} else {
					uni.navigateBack()
				}
			},
			getData() {
				getAllHospital().then(res => {
					this.dataList = res.rows.filter(item=>item.parentCode != 0)
				});
			},
			// @query所绑定的方法不要自己调用！！需要刷新列表数据时，只需要调用this.$refs.paging.reload()即可
			queryList(pageNum, pageSize) {
				// 此处请求仅为演示，请替换为自己项目中的请求
				getAllHospital({
					pageNum,
					pageSize
				}).then(res => {
					console.log(res)
					// 将请求结果通过complete传给z-paging处理，同时也代表请求结束，这一行必须调用
					this.$refs.paging.complete(res.rows);
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		height: 100%;

		.work-container {
			width: 100%;
			height: 100%;
			background-color: #F6F7F9;

			.scroll-view_H {
				width: 100%;
				height: 100%;

				.zp-item {
					border-radius: 12rpx;
					background-color: #fff;
					margin: 20rpx;

					.item-title {
						display: flex;
						align-items: center;
						justify-content: space-between;

						text {
							color: #fff;
							background-color: #4D8EFF;
							font-size: 30rpx;
							padding: 8rpx 12rpx;
							border-radius: 10rpx;
						}

						.btn {
							padding: 4px 6px;
							background: #4D8EFF;
							color: #fff;
							font-size: 0.6rem;
							border-radius: 4px;
						}

					}
				}

			}

		}

	}
</style>
